<html>
<head><meta charset="utf-8"><title>How do I get the features active in another crate? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html">How do I get the features active in another crate?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226973064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226973064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226973064">(Feb 19 2021 at 14:49)</a>:</h4>
<p><code>tcx.features()</code> gives me the features active in the current crate. How do I get the features active in an arbitrary crate?</p>



<a name="226973221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226973221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226973221">(Feb 19 2021 at 14:50)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.features_query">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.features_query</a> looks right</p>



<a name="226974474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226974474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226974474">(Feb 19 2021 at 15:00)</a>:</h4>
<p>didn't work:</p>
<div class="codehilite"><pre><span></span><code>thread &#39;rustc&#39; panicked at &#39;assertion failed: `(left == right)`
  left: `crate2`,
 right: `crate0`&#39;, compiler/rustc_middle/src/ty/context.rs:2759:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</code></pre></div>



<a name="226976138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226976138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226976138">(Feb 19 2021 at 15:11)</a>:</h4>
<p>You could try getting the list of attributes of the crate root for said crate and then calculating the list of active features from that.</p>



<a name="226976218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226976218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226976218">(Feb 19 2021 at 15:11)</a>:</h4>
<p>The list of active features is not directly encoded in the crate metadata.</p>



<a name="226976250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226976250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226976250">(Feb 19 2021 at 15:11)</a>:</h4>
<p>Why do you need it by the way?</p>



<a name="226976339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226976339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226976339">(Feb 19 2021 at 15:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F/near/226976250">said</a>:</p>
<blockquote>
<p>Why do you need it by the way?</p>
</blockquote>
<p><a href="https://github.com/rust-lang/rust/issues/82284">https://github.com/rust-lang/rust/issues/82284</a></p>



<a name="226976359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226976359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226976359">(Feb 19 2021 at 15:12)</a>:</h4>
<p>people can re-export items from another crate</p>



<a name="226979109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226979109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226979109">(Feb 19 2021 at 15:30)</a>:</h4>
<p>do you know where features are calculated for the current crate? I'd like to use the same logic</p>



<a name="226979236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226979236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226979236">(Feb 19 2021 at 15:30)</a>:</h4>
<p>aha, it's <code>rustc_expand::Config::features</code></p>



<a name="226984399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226984399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226984399">(Feb 19 2021 at 16:01)</a>:</h4>
<p>I have a suspicion that we don't retain this information (in the metadata at least)</p>



<a name="226984506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226984506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226984506">(Feb 19 2021 at 16:02)</a>:</h4>
<p>it was in the attributes :) it wasn't too hard to recalculate</p>



<a name="226984524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/226984524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#226984524">(Feb 19 2021 at 16:02)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/82295">https://github.com/rust-lang/rust/pull/82295</a></p>



<a name="227005661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/227005661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#227005661">(Feb 19 2021 at 18:22)</a>:</h4>
<p>note that <a href="http://build.rs">build.rs</a> of a crate can also spoof a feature being active</p>



<a name="227007462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/227007462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#227007462">(Feb 19 2021 at 18:36)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> I mean <code>#![feature(...)]</code>, not cargo features</p>



<a name="227007539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/227007539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#227007539">(Feb 19 2021 at 18:36)</a>:</h4>
<p>cargo features are just a fancy <code>cfg</code> from the perspective of the compiler</p>



<a name="227007667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20do%20I%20get%20the%20features%20active%20in%20another%20crate%3F/near/227007667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20do.20I.20get.20the.20features.20active.20in.20another.20crate.3F.html#227007667">(Feb 19 2021 at 18:37)</a>:</h4>
<p>ah  right</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>